package com.gxpt.app.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gxpt.app.Constant;
import com.gxpt.app.MessageEvent;
import com.gxpt.app.R;
import com.gxpt.app.base.ListBaseAdapter;
import com.gxpt.app.base.SuperViewHolder;
import com.gxpt.app.bean.getaddress_bean;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by Lzx on 2016/12/30.
 */

public class storeaddress_Adapter extends ListBaseAdapter<getaddress_bean.getaddress> {

    //列表图片
//    int pic_view_width = 0;
//    int pic_view_hight = 0;
    Context context;
    public storeaddress_Adapter(Context context) {
        super(context);
        this.context = context;
//        int Sviewwidth  = ScreenUtils.getScreenWidth(context);//
//        pic_view_width  = (Sviewwidth- AppUtils.dip2px(context,10*2))/4;
//        pic_view_hight  = pic_view_width;

//        Logger.i("屏幕 = " + Sviewwidth);
//        Logger.i("宽 = " + pic_view_width);
//        Logger.i("高 = " + pic_view_hight);
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_storeaddress_list;
    }

    @Override
    public void onBindItemHolder(SuperViewHolder holder, int position) {
        final getaddress_bean.getaddress item = mDataList.get(position);

        TextView txt_recipient_name = holder.getView(R.id.txt_recipient_name);
        txt_recipient_name.setText(item.recipient_name);



        TextView txt_mobile_phone = holder.getView(R.id.txt_mobile_phone);
        txt_mobile_phone.setText(item.mobile_phone);

        TextView txt_address = holder.getView(R.id.txt_address);
        txt_address.setText(item.province+item.city+item.region+item.detail_address);

        ImageView img_isdefault = holder.getView(R.id.img_isdefault);

        TextView txt_default = holder.getView(R.id.txt_default);

        if(item.is_default.equals("0")){//0=>非默认 1=>默认
            img_isdefault.setImageResource(R.mipmap.icon_sel_no);
            txt_default.setTextColor(context.getResources().getColor(R.color.font_686868));
        }else{
            img_isdefault.setImageResource(R.mipmap.icon_sel_sel);
            txt_default.setTextColor(context.getResources().getColor(R.color.red));
        }

        LinearLayout toEditInfo = holder.getView(R.id.toEditInfo);
        toEditInfo.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {
                EventBus.getDefault().post(new MessageEvent(Constant.ACTION_TO_EDIT,item.id));
            }
        });

        LinearLayout toDelInfo = holder.getView(R.id.toDelInfo);
        toDelInfo.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {
                EventBus.getDefault().post(new MessageEvent(Constant.ACTION_TO_DEL,item.id));
            }
        });

        LinearLayout toFault = holder.getView(R.id.toFault);
        toFault.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {
                EventBus.getDefault().post(new MessageEvent(Constant.ACTION_TO_DEFAULT,item.id));
            }
        });
    }
}
